home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / POOL.H < prev    next >
C/C++ Source or Header  |  1994-07-31  |  844b  |  42 lines

  1. // Copyright 1994 by Jon Dart.  All Rights Reserved.
  2.  
  3. #ifndef POOL_H
  4. #define POOL_H
  5.  
  6. #include <stddef.h>
  7. #include "types.h"
  8.  
  9. class Pool
  10. {
  11.    // This class defines a simple memory allocator.  Memory is allocated
  12.    // in large chunks, and doled out by "new" into smaller chunks.  Freed
  13.    // memory goes into a free list.  Actual deletion of memory doesn't
  14.    // occur until freeAll() is called.
  15.  
  16. public:
  17.     Pool(const unsigned chunk_size = 4096);
  18.  
  19.     void *allocate( size_t size );
  20.  
  21.     void free( void *p );
  22.  
  23.     void freeAll(Boolean final = False);
  24.  
  25. private:
  26.     struct chunk;
  27.     typedef struct chunk *chunk_ptr;
  28.     struct chunk
  29.     {
  30.     char *mem;
  31.     chunk_ptr next;
  32.     };
  33.  
  34.     chunk * memChain;
  35.     chunk * freeChunks;
  36.     char *nextMem;
  37.     void *freeChain;
  38.     unsigned my_chunk_size;
  39. };
  40.  
  41. #endif
  42.